#:import A kivy.animation.Animation
#:import rgba kivy.utils.get_color_from_hex
#:set ICON_PLAY "P"
#:set ICON_REFRESH "R"
#:set ICON_KIVY "K"

<IconLabel@Label>:
    font_name: "data/kivylauncher.ttf"

<IconButton@ButtonBehavior+IconLabel>
    size_hint_x: None
    width: self.height
    canvas.before:
        Color:
            rgba: rgba("#ffffff66") if self.state == "down" else rgba("#00000000")
        Rectangle:
            pos: self.pos
            size: self.size

<LLabel@Label>:
    text_size: self.width, None

<TopBar@GridLayout>:
    rows: 1
    padding: dp(4)
    size_hint_y: None
    height: dp(48)
    spacing: dp(10)
    canvas.before:
        Color:
            rgba: rgba("#3F51B5")
        Rectangle:
            pos: self.pos
            size: self.size

    IconLabel:
        text: ICON_KIVY
        size_hint_x: None
        width: self.height
    Label:
        text: "Kivy Launcher"
        size_hint_x: None
        width: self.texture_size[0]
        font_size: dp(16)
        font_name: "data/Roboto-Medium.ttf"

    IconButton:
        text: ICON_REFRESH
        on_press:
            app.refresh_entries()

    ToggleButton:
        text: 'Show logs' if self.state == 'normal' else 'Hide logs'
        state: 'down' if app.display_logs else 'normal'
        on_state:
            app.display_logs = self.state == 'down'


<LauncherEntry@BoxLayout>:
    data_title: ""
    data_orientation: ""
    data_logo: "data/logo/kivy-icon-64.png"
    data_orientation: ""
    data_author: ""
    data_entry: None
    padding: dp(4)
    spacing: dp(8)
    canvas.before:
        Color:
            rgba: rgba("#eeeef0")
        Rectangle:
            pos: self.x + self.height + self.padding[0], self.y - self.padding[1] / 2.
            size: self.width, dp(1)

    Image:
        source: root.data_logo
        size_hint_x: None
        width: self.height
    BoxLayout:
        orientation: "vertical"
        padding: 0, dp(4)
        LLabel:
            text: root.data_title
            color: rgba("#454547")
            font_name: "data/Roboto-Medium.ttf"
            font_size: dp(13)
        LLabel:
            text: root.data_author
            color: rgba("#b4b6b7")
            font_size: dp(11)
    IconButton:
        text: ICON_PLAY
        on_release: app.start_activity(root.data_entry)
        color: rgba("#b4b6b8")


GridLayout:
    cols: 1
    canvas.before:
        Color:
            rgba: rgba("#fafafc")
        Rectangle:
            size: self.size
    TopBar
    FloatLayout:
        RecycleView:
            id: rv
            pos_hint: {'pos': (0, 0)}
            viewclass: "LauncherEntry"
            RecycleBoxLayout:
                size_hint_y: None
                height: self.minimum_height
                orientation: "vertical"
                spacing: dp(2)
                default_size: None, dp(48)
                default_size_hint: 1, None

        RecycleView:
            viewclass: 'LogLabel'
            data: [{'text': log} for log in app.logs]
            _top: 0
            pos_hint: {'top': self._top, 'x': 0}
            visible: app.display_logs
            on_visible:
                A.cancel_all(self, '_top')
                A(_top=1 if self.visible else 0, d=.3, t='out_quad').start(self)

            canvas.before:
                Color:
                    rgba: rgba("#CCCCCCCC")
                Rectangle:
                    pos: self.pos
                    size: self.size

            RecycleBoxLayout:
                orientation: 'vertical'
                size_hint_y: None
                height: self.minimum_height
                default_size_hint: None, None
                default_size: 0, 20
                padding: 5, 5

        Label:
            text:
                '''
                Please install applications in one of the following directories
                - {}
                '''.format('\n -'.join(app.paths))
            pos_hint: {'pos': (0, 0)}
            color: rgba("#222222" if not rv.data else "#00000000")

<LogLabel@Label>:
    color: rgba("#222222FF")
    pos_hint: {'x': 0}
    width: self.texture_size[0]
